package compare;

import com.sun.org.apache.xpath.internal.operations.String;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @Author Klys
 * @Date 2023/6/25 17:44
 * @Description
 * @Version 1.0
 */
public class LambdaDemo {

    public static void main(String[] args) {
        Student student1 = new Student(25, "klys");
        Student student2 = new Student(21, "liuyusong");
        Student student3 = new Student(22, "liu");
        List<Student> studentList = Arrays.asList(student1, student2, student3);

        Comparator<Student> ageComp = (s1, s2) -> s1.getAge() - s2.getAge();
        studentList.sort(ageComp);
        System.out.println(studentList);

        Comparator<Student> nameComp = (s1, s2) -> s1.getName().compareTo(s2.getName());
        studentList.sort(nameComp);
        System.out.println(studentList);

    }
}
